<template>
	<view>
		<view class="message">
			<view class="header">
				<view class="desc">{{ sendTime }}</view>
				<view class="opt" @tap="deleteMsg()">删除</view>
			</view>
			<view class="content">
				<view class="sender">
					<image :src="senderPhoto" mode="widthFix" class="photo" />
					<text>{{ senderName }}</text>
				</view>
				<view class="msg">{{ msg }}</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			id: null,
			readFlag: null,
			refId: null,
			senderName: '',
			sendTime: '',
			senderPhoto: '',
			msg: ''
		};
	},
	onShow: function() {
		
	},
	onLoad: function(options) {
		let that = this;
		that.id = options.id;
		that.refId = options.refId;
		let data = {
			"id": that.id,
			"refId": that.refId
		}
		this.ajax(this.url.searchMessageById, 'POST', data, function(resp){
			let result = resp.data.result;
			that.readFlag = result.readFlag;
			that.senderName = result.senderName;
			that.sendTime = result.sendTime;
			that.senderPhoto = result.senderPhoto;
			that.msg = result.msg;
			//标记为已阅读
			let data2 = {
				"id": that.refId
			}
			that.ajax(that.url.updateUnreadMessage, 'POST', data2, function(resp){}, false)
		})
	},
	methods: {
		deleteMsg() {
			let that = this;
			let data = {
				"id": that.refId
			}
			this.ajax(this.url.deleteMessageRefById, 'POST', data, function(resp){
				if(resp.data.rows == 1) {
					self.$refs.uToast.show({
						title: '删除成功',
						duration: 500,
						type: 'success',
						callback(){
							uni.navigateTo({
								url: '../message_list/message_list'
							});
						}
					});
				}
			})
		}
	}
};
</script>

<style lang="less">
@import url('message.less');
</style>
